home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 5 / BBS in a Box -Volume V (BBS in a Box) (April 1992).iso / Files / Prog / Q-R / REdExamples.cpt / Examples / PExamples / ResXXXXEd.p / ResXXXXEd.p
Encoding:
Text File  |  1988-08-01  |  6.8 KB  |  241 lines  |  [TEXT/MPS ]

  1. {
  2. File ResXXXXEd.p
  3.  
  4. Copyright Apple Computer, Inc. 1985-1988
  5. All rights reserved.
  6. }
  7.  
  8. UNIT ResXXXXed;
  9.   {XXXX Editor for ResEdit}
  10.  
  11.   INTERFACE
  12.  
  13.     USES {$U Memtypes.p } Memtypes,
  14.       {$U QuickDraw.p } QuickDraw,
  15.       {$U OSIntf.p    } OSIntf,
  16.       {$U ToolIntf.p } ToolIntf,
  17.       {$U PackIntf.p } PackIntf,
  18.       {$U ResEd.p    } ResEd;
  19.       {$R-} {Range checking off }
  20.  
  21.     TYPE
  22.       rXXXXPtr      = ^rXXXXRec;
  23.       rXXXXHandle = ^rXXXXPtr;
  24.       rXXXXRec      = RECORD
  25.                       father: ParentHandle; {Back ptr to dad }
  26.                       name: str64; {the name of this editor }
  27.                       windPtr: WindowPtr; {This view's window}
  28.                       rebuild: BOOLEAN; {Set TRUE if things have changed}
  29.                       hXXXX: Handle; {The resource we are working on}
  30.                       menuXXXX: Menuhandle; {our menu }
  31.                     END; {rXXXXRec}
  32.  
  33.     PROCEDURE EditBirth(Thing: Handle; Dad: ParentHandle);
  34.  
  35.     PROCEDURE PickBirth(t: ResType; Dad: ParentHandle);
  36.  
  37.     PROCEDURE DoEvent(VAR Evt: EventRecord; MyXXXX: rXXXXHandle);
  38.  
  39.     PROCEDURE DoInfoUpdate(oldID, newID: INTEGER; MyXXXX: rXXXXHandle);
  40.  
  41.     PROCEDURE DoMenu(Menu, Item: INTEGER; MyXXXX: rXXXXHandle);
  42.  
  43.   IMPLEMENTATION
  44.  
  45.       {- -    -  -  - -  -  -  - -  -  -    - -  -    -  - -    -  -  - -  -  -}
  46.  
  47.     PROCEDURE EditBirth{Thing:Handle;Dad:ParentHandle};
  48.  
  49.       VAR
  50.         MyXXXX: rXXXXHandle;
  51.         w: WindowPtr;
  52.         s: str255;
  53.  
  54.       BEGIN {EditBirth}
  55.         {Prepare window title and request creation of a new window}
  56.         s := 'Window';
  57.         SetETitle(Handle(Thing), s);
  58.         ConcatStr(s, ' from ');
  59.         w := WindSetup(300, 100, s, Dad^^.name);
  60.         {If we got a new window, then start up the editor}
  61.         IF ORD(w) <> 0 THEN
  62.           BEGIN
  63.           FixHand(SIZEOF(WindowRecord), Handle(Thing)); {Make sure we have
  64.                                                          enough room in }
  65.           {the handle for a complete window }
  66.           {record. (later this will be        }
  67.           {assigned to MyXXXX^^.hXXXX        }
  68.  
  69.           {Get memory for and handle to our instance record}
  70.           MyXXXX := rXXXXHandle(NewHandle(SIZEOF(rXXXXRec)));
  71.           HLock(Handle(MyXXXX));
  72.           WITH MyXXXX^^ DO
  73.             BEGIN
  74.          {Put information about this incarnation of the editor and the window it is }
  75.          {serving into our record.(always passed around in the handle MyXXXX.  }
  76.             windPtr := w;
  77.             father := Dad;
  78.             hXXXX := Thing;
  79.                {Let the main program know who is to manage this window by giving it both   }
  80.             {our resource ID number and our instance record handle       }
  81.             WITH WindowPeek(w)^ DO
  82.               BEGIN
  83.               windowKind := ResEdID;
  84.               refCon := ORD(MyXXXX);
  85.               END; {WITH}
  86.             END; {WITH}
  87.           {Set up menus,the view, etc. for this window}
  88.           HUnlock(Handle(MyXXXX));
  89.           END; {IF ORD(w)<>0}
  90.       END; {EditBirth}
  91.     {- -  -  -    - -  -    -  - -    -  -  - -  -  -  - -  -  -    - -  -    -}
  92.  
  93.     PROCEDURE PickBirth{t:ResType;Dad:ParentHandle};
  94.  
  95.       BEGIN {PickBirth}
  96.       END; {PickBirth}
  97.     {- -  -  -    - -  -    -  - -    -  -  - -  -  -  - -  -  -    - -  -    -}
  98.  
  99.     PROCEDURE DoEvent{VAR Evt:EventRecord;MyXXXX:rXXXXHandle};
  100.  
  101.       VAR
  102.         MousePoint: Point;
  103.         act: BOOLEAN;
  104.  
  105.       BEGIN {DoEvent}
  106.         BubbleUp(Handle(MyXXXX)); {Move our item up im memory}
  107.         HLock(Handle(MyXXXX)); {Lock it down }
  108.         WITH MyXXXX^^ DO
  109.           BEGIN {Handle event passed to us by main program}
  110.           {Just like a 'real' event loop, except…          }
  111.           {there is no loop and we don't have to          }
  112.           {handle as much because the main program          }
  113.           {will do all the stuff that doesn't apply       }
  114.           {to us.                                          }
  115.           MousePoint := Evt.where; {Point at which the event occured }
  116.           SetPort(windPtr); {Set the port to our window }
  117.           GlobalToLocal(MousePoint); {Convert event location to local coords}
  118.           CASE Evt.what OF
  119.             mouseDown:
  120.               BEGIN
  121.               END; {mouseDown}
  122.             activateEvt:
  123.               BEGIN
  124.               AbleMenu(fileMenu, filetop);
  125.               act := ODD(Evt.modifiers);
  126.               IF act THEN
  127.                 BEGIN {Activate event}
  128.                 END   {Activate event}
  129.               ELSE
  130.                 BEGIN {Deactivate event}
  131.                 END;  {Deactivate event}
  132.               END {activateEvt} ;
  133.             updateEvt:
  134.               BEGIN
  135.                 PaintRect(windPtr^.portrect);
  136.               END; {updateEvt}
  137.             keyDown:
  138.               BEGIN
  139.               END; {keyDown}
  140.           END; {CASE evt.what}
  141.           END; {WITH MyXXXX^^}
  142.         HUnlock(Handle(MyXXXX));
  143.       END; {DoEvent}
  144.     {- -  -  -    - -  -    -  - -    -  -  - -  -  -  - -  -  -    - -  -    -}
  145.  
  146.     PROCEDURE DoInfoUpdate{oldID,newID:INTEGER;MyXXXX:rXXXXHandle};
  147.  
  148.       VAR
  149.         s: str255;
  150.  
  151.       BEGIN {DoInfoUpdate}
  152.         WITH MyXXXX^^ DO
  153.           BEGIN {Since our ID has changed, we need to change our window title}
  154.           s := 'Window';
  155.           SetETitle(Handle(hXXXX), s);
  156.           ConcatStr(s, ' from ');
  157.           ConcatStr(s, father^^.name);
  158.           SetWTitle(windPtr, s);
  159.           {Now, let our father object know that our ID has been changed}
  160.           CallInfoUpdate(oldID, newID, father^^.wind^.refCon,
  161.                          father^^.wind^.windowKind);
  162.           END; {WITH MyXXXX^^}
  163.       END; {DoInfoUpdate}
  164.     {- -  -  -    - -  -    -  - -    -  -  - -  -  -  - -  -  -    - -  -    -}
  165.  
  166.     PROCEDURE DoMenu{Menu,Item:INTEGER;MyXXXX:rXXXXHandle};
  167.  
  168.       VAR
  169.         saveRefNum: INTEGER;
  170.  
  171.       PROCEDURE DoClose;
  172.  
  173.         BEGIN
  174.           WITH MyXXXX^^ DO
  175.             BEGIN
  176.             CloseWindow(windPtr); {Close the window }
  177.             WindFree(windPtr); {Mark the window record as being available}
  178.             InitCursor; {Make sure the cursor is the arrow cursor }
  179.             {Delete any menus that we added and redraw menu bar   }
  180.             {Be sure to dispose of any handles you are done with  }
  181.             END; {WITH MyXXXX^^}
  182.           DisposHandle(Handle(MyXXXX));
  183.         END; {DoClose}
  184.  
  185.       BEGIN {DoMenu}
  186.         BubbleUp(Handle(MyXXXX));
  187.         HLock(Handle(MyXXXX));
  188.         WITH MyXXXX^^ DO
  189.           BEGIN
  190.           SetPort(windPtr); {Set the port to our window}
  191.       {Again, we handle the menu stuff just as we would in a 'real' application}
  192.       {except that we only have to handle those items that apply to ourselves. }
  193.           CASE Menu OF
  194.             fileMenu:
  195.               CASE Item OF
  196.                 CloseItem:
  197.                   BEGIN
  198.                   DoClose; {Close our window }
  199.                   EXIT(DoMenu); {Return to main program}
  200.                   END; {CloseItem}
  201.                 RevertItem:
  202.                   BEGIN
  203.                   {The area under window will need to be updated}
  204.                   InvalRect(windPtr^.portrect);
  205.                   {We will need to restore the cur resource file    }
  206.                   {reference number when we are done here.            }
  207.                   saveRefNum := CurrentRes;
  208.                   {We are going to be using the resource file we    }
  209.                   { came from.                                        }
  210.                   UseResFile(HomeResFile(Handle(hXXXX)));
  211.                   {Read in the old copy from disk (see documentation}
  212.                   {for revertResource).  Clear it out unless this    }
  213.                   { was a newly created resource, in which case     }
  214.                   {don't.                                           }
  215.                   IF NOT RevertResource(Handle(hXXXX)) THEN
  216.                     BEGIN
  217.                     RmveResource(Handle(hXXXX));
  218.                     MyXXXX^^.father^^.rebuild := TRUE;
  219.                     DoClose;
  220.                     EXIT(DoMenu);
  221.                     END; {IF NOT RevertResource…}
  222.                   {Go back to using old resource file.       }
  223.                   UseResFile(saveRefNum);
  224.                   END; {RevertItem}
  225.                 GetInfoItem:
  226.                   BEGIN
  227.                   ShowInfo(Handle(hXXXX), ParentHandle(MyXXXX));
  228.                   END; {GetInfoItem}
  229.               END; {FileMenu: CASE Item OF}
  230.             EditMenu:
  231.               CASE Item OF
  232.                 CutItem:   ;
  233.                 CopyItem:  ;
  234.                 PasteItem: ;
  235.                 ClearItem: ;
  236.               END; {EditMenu: CASE Item OF}
  237.           END; {CASE Menu OF }
  238.           END; {WITH MyXXXX^^}
  239.       END; {DoMenu}
  240. END.
  241.